#!/bin/bash
#
#<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=fastcgi" title="View all posts in fastcgi" target="_blank">fastcgi</a></span>??? Start/Stop <span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=php-cgi" title="View all posts in php-cgi" target="_blank">php-cgi</a></span>
#
#write by wenzi at 2009-11-02
spawn_fcgid=/usr/local/<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=php" title="View all posts in php" target="_blank">php</a></span>/bin/<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=spawn-fcgi" title="View all posts in spawn-fcgi" target="_blank">spawn-fcgi</a></span>
<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=php" title="View all posts in php" target="_blank">php</a></span>_cgid=/usr/local/<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=php" title="View all posts in php" target="_blank">php</a></span>/bin/<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=php-cgi" title="View all posts in php-cgi" target="_blank">php-cgi</a></span>
php_cgi_pid=/usr/local/nginx/logs/php-cgi.pid
php_cgi_ip=127.0.0.1
php_cgi_port=9000
php_cgi_process_num=200
php_cgi_user=daemon
php_cgi_group=daemon
prog="php-cgi"

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
if [ "$NETWORKING" = "no" ]; then
    exit 0
fi

[ -f ${spawn_fcgid} ] || exit 0

RETVAL=0

#Start php-cgi daemons functions.
start() {
    if [ -e ${php_cgi_pid} ];then
        ps ax|grep "php-cgi"|grep -v grep &>/dev/null
        if ps ax|grep "php-cgi"|grep -v grep &>/dev/null;then
            echo -n "php-cgi already running...."
            exit 1
        else
            rm -f ${php_cgi_pid}
        fi
    fi
    echo -n $"Starting $prog: "
    daemon ${spawn_fcgid} -a ${php_cgi_ip} -p ${php_cgi_port} -f ${php_cgid} -C ${php_cgi_process_num} -P ${php_cgi_pid} -u ${php_cgi_user} -g ${php_cgi_group}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/php-cgi
    return $RETVAL
}

#Stop php-cgi daemon funtions.
stop() {
    echo -n $"Stopping $prog:"
    killproc ${php_cgid}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/php-cgi /var/run/<span class='wp_keywordlink_affiliate'><a href="http://www.wenzizone.cn/?tag=spawn-fcgi" title="View all posts in spawn-fcgi" target="_blank">spawn-fcgi</a></span>.pid
}

# See how we were called
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
status)
    status $prog
    RETVAL=$?
    ;;
*)
    echo $"Usage:$prog{start|stop|restart|status|help}"
    exit 1
esac
exit $RETVAL
